package oj;

import java.util.Random;

/**
 * @author 郝文雪
 * @date 2022/8/10 17:40
 * @Description 蓄水池抽样问题
 */
public class LC382 {
    ListNode head;
    Random random;
    public LC382(ListNode head) {
        this.head=head;
        this.random=new Random();
    }
    public int getRandom() {
        int i=1;
        int ans=0;
        int c=0;
        for(ListNode node=head;node!=null;node=node.next){
            if(random.nextInt(i)==0){
                ans=node.val;
            }
            i++;
        }
        return ans;
    }
}
